<template>
	<view class="publish">
		<view class="fixed-header">
			<view class="my-publish flex-x-c b-w" v-if="identifying === 'enterprise'">
				<view class="flex-y-c">
					<view class="publish-num">{{ total }}</view>
					<view>{{tabWord}}</view>
				</view>
				<view class="publish-btn" @click="goPublish">
					<u-button type="primary" text="立即发布"></u-button>
				</view>
			</view>
			<view class="b-w tab-shadow">
				<u-tabs 
					:list="tabList" 
					:current="currentTab" 
					itemStyle="width: 25%;line-height: 100rpx;box-sizing: border-box;" 
					@change="changeTab">
				</u-tabs>
			</view>
		</view>
		<view class="publish-list" :style="identifying === 'enterprise'?'padding-top: 240rpx':''">
			<view class="publish-list__card" v-for="item in listData" :key="item.id">
				<publish-item :info="item"></publish-item>
			</view>
			<view class="more">
				<u-loadmore :status="status"/>
			</view>
		</view>
	</view>
</template>

<script>
	import publishItem from './components/publishItem'
	// 全部-''，待审核-0，通过-1，拒绝-2
	const audit = {
		0: '',
		1: 0,
		2: 1,
		3: 2
	}
	export default { 
		components: { publishItem },
		data() {
			return {
				currentTab: 0,
				tabList: [
					{
						name: '全部',
					}, {
						name: '待审核',
					}, {
						name: '通过'
					}, {
						name: '拒绝'
					}
				],
				//身份类型：管理员-admin，部门-dept，专家-professional，企业-enterprise，经理人-manager， 空为游客
				// identifying: '',
				postLink: '',
				parm: {
					pageNo: 1,
					pageSize: 10,
					audit: '',
					pageLock : false
				},
				listData: [],
				total: 0,
				status: 'loading'
			}
		},
		computed: {
			tabWord() {
				const wordList = ['发布总数', '待审核总数', '已发布总数', '被拒绝总数']
				return wordList[this.currentTab]
			}
		},
		onLoad(options) {
			this.currentTab = options.type || 0
			this.parm.audit = audit[this.currentTab]
			// this.identifying = this.$globalData.state.userInfoDetail.identifying
			if(this.identifying === 'admin') {
				this.postLink = '/enterprisePublishApply/enterprisePublishApplyPage'
				uni.setNavigationBarTitle({ title: '发布审核' })
			} else if (this.identifying === 'enterprise') {
				this.postLink = '/enterprisePublishApply/myEnterprisePublishApplyPage'
			}
			this.getList()
		},
		onShow() {
			this.parm.pageNo = 1
			this.listData = []
			this.parm.pageLock = false
			this.getList()
		},
		onReachBottom() {
			this.parm.pageNo++
			this.getList()
		},
		methods: {
			getList() {
				if (this.parm.pageLock) return
				if (this.requesting) return
				this.requesting = true
				this.status = 'loading'
				this.$request(this.postLink, this.parm).then(res => {
					if(this.parm.pageNo === 1) this.listData = []
					this.listData = [...this.listData, ...res.result.records]
					this.total = res.result.total
					this.parm.pageLock = this.listData.length >= this.total
					this.status = 'nomore'
				}).finally(() => this.requesting = false)
			},
			changeTab(e) {
				this.parm.pageNo = 1
				this.parm.pageLock = false
				this.currentTab = e.index
				this.listData = []
				this.parm.audit = audit[this.currentTab]
				this.getList()
			},
			goPublish() {
				this.$routeUtils.navigateTo({
				  url: '/pages/user/publish'
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.publish{
		.fixed-header{
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			/*  #ifdef  H5 */
			top: 88rpx;
			/*  #endif  */
			z-index: 10;
		}
	}
	.my-publish{
	  width: 750rpx;
		height: 120rpx;
		justify-content: space-between;
		padding: 0 20rpx;
		box-sizing: border-box;
	}
	.publish-btn{
		width: 200rpx;
		.u-icon{
			font-size: 24rpx;
		}
	}
	.publish-num{
		font-size: 32rpx;
		color: $uni-color-primary;
	}
	.tab-shadow{
		box-shadow: 0px 0px 3px 0px rgba(0, 0, 0, 0.1);
	}
	.publish-list{
		padding: 120rpx 20rpx 0 20rpx;
		.publish-list__card {
			margin-bottom: 20rpx;
		}
	}
	.more{
		padding-bottom: 50rpx;
	}
</style>